import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from "path"
//vant 按需引用
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';
//nutui 样式按需导入
import { createStyleImportPlugin } from 'vite-plugin-style-import'
// https://vitejs.dev/config/
export default defineConfig({
  server: {
    host: '0.0.0.0', // 解决不能通过ip访问
    port:4000,
    cors: true,
    proxy:{
      '/yccsqx/': {
        //target: `http://10.124.102.7:8060`, //现场
       //target: `http://111.229.73.147:30108/`,//公网
       target:'https://www.ycsqxj.com/',
       changeOrigin: true,
      }
    }
  },
  build:{
    outDir: 'dist',
    
  },
  base: './',
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue',"vue-router"], 
      dts: 'src/auto-import.d.ts',
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
    createStyleImportPlugin({
      resolves: [{
          libraryName: '@nutui/nutui',
          libraryNameChangeCase: 'pascalCase',
          resolveStyle: (name) => {
            return `@nutui/nutui/dist/packages/${name.toLowerCase()}/index.scss`
          },
      }]
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        // 配置 nutui 全局 scss 变量
        additionalData: `@import "@nutui/nutui/dist/styles/variables.scss";`
      }
    }
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
      'nutui': 'nutui/dist/nutui.esm.js'
    }
  }
})
